﻿using System.Linq;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using Samurai.Wakizashi.Caching;

// ReSharper disable InconsistentNaming
namespace Samurai.Caching.Tests
{
    [TestClass]
    public class CacheStore_Tests
    {
        [TestMethod]
        public void Provides_an_enumerable_collection_of_all_items_in_the_cache()
        {
            var cache = new CacheStore<CacheItem>();
            cache.CacheItem(new CacheItem());

            Assert.IsTrue(cache.AllItems.Count() ==1);
        }

        [TestMethod]
        public void Caches_items()
        {
            var cache = new CacheStore<CacheItem>();
            cache.CacheItem(new CacheItem());

            Assert.IsTrue(cache.AllItems.Count() == 1);
        }

        [TestMethod]
        public void Evicts_specified_item_from_cache()
        {
            var cacheItem = new CacheItem {Prop1 = "xxx"};
            var cache = new CacheStore<CacheItem>();
            cache.CacheItem(cacheItem);
            cache.EvictItem(cacheItem);

            Assert.IsTrue(cache.AllItems.Count() == 0);
        }

        [TestMethod]
        public void Clears_all_items_from_cache()
        {
            var cacheItem = new CacheItem { Prop1 = "xxx" };
            var cacheItem2 = new CacheItem { Prop1 = "zxzz" };
            var cache = new CacheStore<CacheItem>();
            cache.CacheItem(cacheItem);
            cache.CacheItem(cacheItem2);
            cache.Clear();

            Assert.IsTrue(cache.AllItems.Count() == 0);
        }
    }
}
// ReSharper restore InconsistentNaming